package com.xiayuxuanmin.weixinpay.servlet;

import com.sun.net.httpserver.HttpsServer;

import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * 返回生成的二维码图片的servlet
 * @Author xiayuxuanmin
 * @Date 2019/8/10
 * @Description
 */
public class ImageServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        BufferedImage image = (BufferedImage) req.getSession().getAttribute("image");
        //把图片image以JPEG的格式写入到输出流中
        ImageIO.write(image,"JPEG", resp.getOutputStream());
    }
}
